<!doctype html>
<html>
  <head>
  <link rel="icon" 
      type="image/png" 
      href="favicon.png">
      
      <title>fasttimesheet</title>
  	<meta http-equiv="content-type" content=""text/htm; charset=UTF-8" >
	<link href="default.css" rel="stylesheet" type="text/css">
    <script type="text/javascript" src="jquery/jquery.js"></script>
    
    
	<link href="jquery/jquery-ui.css" rel="stylesheet" type="text/css"/>
  	<script src="jquery/jquery-ui.min.js"></script>
  	
  	
 <link rel="stylesheet" href="jquery-ui-1.8.4.custom.css" type="text/css" />
<link rel="stylesheet" href="jquery/jquery.autocomplete.css" type="text/css" />
  <script type="text/javascript" src="jquery/jquery.bgiframe.min.js"></script>
  
  <script type="text/javascript" src="jquery/jquery.autocomplete.js"></script>  	
  	<script type="text/javascript" src="jquery/jquery.jeditable.js"></script>
  	
  	<script type="text/javascript" src="jquery/jquery.idle-timer.js"></script>
  	
  
    <script type="text/javascript">
     
    </script>
  </head>
  <body>
  <style type="text/css">
	.ui-autocomplete-loading { background: white url('images/ui-anim_basic_16x16.gif') right center no-repeat; }
	</style>
<script>

function alerter() {
	alert("lol");	
	}
	
function totimesetter() {
	$.post("core/timesetter.php", { 
  			from: $("#from").val(),
  			duration: $("#duration").val(),
  			action: "to"
  			}, 
  			function(data){
   		$('#to').val(data);
   		
 			}); 
	}

function durationsetter() {
	$.post("core/timesetter.php", { 
  			from: $("#from").val(),
  			to: $("#to").val(),
  			action: "duration"
  			}, 
  			function(data){
   		$('#duration').val(data);
   		
 			}); 
	}

function timeinitializer() {
	
	$.post("visual/lasttasktime.php",function(data){
   		$('#from').val(data);
   		totimesetter();
 			}); 
	}

function validatetime(tim,id) {
	$.post("core/validatetime.php",{value: tim, id: id},function(data){
			//alert(data);   		
			$('#info').html(data);
			errordialog();
   		}); 
	}
	
function validatetime_to(tim,id) {
	$.post("core/validatetime_to.php",{value: tim, id: id},function(data){
			//alert(data);   		
			$('#info').html(data);
			errordialog();
   		}); 
	}	
function changejob(id) {
	$("#changejobdesc").val('');
	$('#changejobid').val(''); 
	$('#changeuserjobid').val(id); 
	$("#changejob").dialog({
			modal: true,
			minWidth: 400,
			height: 600,
			buttons: {
				Cancel: function() {
					$(this).dialog('close');
				}
			}
		});	
}

function loadsettings() {
	$.post("visual/loadsettings.php", function(data){
	$('#settings').html(data);
		});
	}


function settings_dialog() {
	$("#settings").dialog({
			modal: true,
			buttons: {
				Cancel: function() {
					$(this).dialog('close');
				},
				Ok: function() {
					$.post("visual/changestart.php",{ 
  					value: $('#settings_starttime').val()
  					},function(data) {
					loadsettings();
  					//alert(data);
  					});	
				
				$(this).dialog('close');	
				}
			}
		});	
}

function setautostart(checked) {
	//alert($(this+":checked").val());
	if ($(this+":checked").val() == "on") {
		$('#settings_starttime').attr('disabled', 'disabled');
		$('#settings_starttime').val('auto');		
		} else {
		$('#settings_starttime').attr('disabled', '');
		}
	}


 function loadtasks() 
	{
	$.post("visual/taskcaller.php", function(data){
   $('#mainview').html(data);
   timeinitializer();
   $('.edit').editable('core/editnote.php',{style: "inherit"});
   $('.edittimefrom').editable('core/jobtimeeditor.php',{style: "inherit", callback : function(value, settings) {
		    
        loadtasks() ;
        //alert(this.id); 
        validatetime(value,this.id);	
         
	     }
     });
   $('.edittimeto').editable('core/jobtimeeditor_to.php',{style: "inherit",callback : function(value, settings) {
		    
        loadtasks() ;
        //alert(this.id); 
        validatetime_to(value,this.id);	
         
	     }
     });
     tasklit();
 	});
	};
function tasklit() {
	$(".onetask").hover(function() {
		//alert('lol');
  		$(this).addClass('rowlit');
  		//$(this).animate({ backgroundColor: "green", opacity: 0.85 }, 50);
		}, function() {
  		$(this).removeClass('rowlit');
		});
	}

function setjobid() {
	$.post("core/getjobid.php",{ 
  					jobpath: $("#jobpicker").val()
  					},function(data) {
					$('#jobid').val(data);  			
  					});	
	};
	
function setjob(id) {
	$.post("core/returnpath.php",{ 
  			id: id
  			},function(data) {
			$('#thisjob').html(data);
			$("#jobpicker").val(data);
			$('#jobid').val(id);  			
  			});	
	}
	
function setjob2(id) {
	$.post("core/returnpath.php",{ 
  			id: id
  			},function(data) {
			//$('#changejob').title(data);
			$("#changejobdesc").val(data);
			$('#changejobid').val(id); 
			$('#changejob').dialog('close'); 
			$.post("core/changejob.php",{ 
  				jid: id,
  				ujid: $('#changeuserjobid').val(),
  				jdesc: data 
  				},function(data) {
				loadtasks();
				});			
  			});	
	}

function deletetask(id) {
		$.post("core/taskdeleter.php",{ 
  			id: id
  			}, 
  		function(data){
  			
   		loadtasks();
 			});
	}
	
function attendance() {
	$.post("visual/getattend.php", function(data){
	 	$('#attend').html(data);
	 	$(".editattend").editable("visual/setattendance.php", { 
	            style  : "inherit",
	            callback : function(value, settings) {
	            		attendance();
     				}
  			});
 		});
	}
	
//element visualisation functions
function treeaccordeon() {
	 $("#tree").accordion({
			collapsible: true,
			active: false,
			autoHeight: false,
			fillSpace: true
		});
	
	//$("#selectablejob").selectable();
	}

function selectanimate() {
	$(".hovertoggle").hover(function() {
		$(this).animate({ backgroundColor: "#68BFEF", opacity: 0.7 }, 100);
		});
	$(".hovertoggle").mouseleave(function() {
    		$(this).animate({ backgroundColor: "#b2aeae", opacity: 0.75 }, 100);
		});
	}
	
function errordialog() {
	if ($("#info").html() != "") {
	//alert ();
	$("#info").dialog({
			modal: true,
			minWidth: 400,
			buttons: {
				Ok: function() {
					$(this).dialog('close');
				}
			}
		});
	}
}


function selectext(id) {
	alert(id);
	$(id).focus();
	$(id).select();
}

$(document).ready(function(){
   $.post("visual/treecaller.php", function(data){
   $('#tree').html(data);
   //$('#changejob').html(data);
   treeaccordeon();
   selectanimate();
 });
 });
 
 $(document).ready(function(){
   $.post("visual/changetreecaller.php", function(data){
   //$('#tree').html(data);
   $('#changejob').html(data);
   selectanimate();
 });
 });
 
 $(document).ready(function(){
   $.post("visual/loadsettings.php", function(data){
   $('#settings').html(data);
 });
 });
 
 
$(document).ready(function(){
	
	$("#datepicker").datepicker({ altFormat: 'yy-mm-dd' });
	loadtasks();
	attendance();
	});
	
$(document).ready(function(){
	
	$("#datepicker").change(function() {
  		$.post("core/datechecker.php",{ 
  			date: $("#datepicker").val()
  			}, 
  		function(data){
   		$('#info').html(data);
   		errordialog();
 			});
 		$.post("core/datesetter.php",{ 
  			date: $("#datepicker").val()
  			},function(data) {
			loadtasks();  	
			attendance();		
  			});
	
	});
	
	$('#next_day').click(function(){
		$.post("core/datechanger.php",{ 
  			action: "+1"
  			}, 
  		function(data){
   		$('#datepicker').val(data);
   		totimesetter();
   		loadtasks();
   		attendance();
 			});	
	});
	$('#previous_day').click(function(){
		$.post("core/datechanger.php",{ 
  			action: "-1"
  			}, 
  		function(data){
   		$('#datepicker').val(data);
   		totimesetter();
   		loadtasks();
   		attendance();
 			});	
	});

});

$(document).ready(function(){
	$("#from").change(function() {
  		$.post("core/timechecker.php",{ 
  			time: $("#from").val()
  			}, 
  		function(data){
   		$('#info').html(data);
   		errordialog();
   		totimesetter();
 			});
 		});
 	$("#to").change(function() {
  		$.post("core/timechecker.php",{ 
  			time: $("#to").val()
  			}, 
  		function(data){
   		$('#info').html(data);
   		errordialog();
   		durationsetter();
 			});
 		});
 	$("#duration").change(function() {
  		$.post("core/timechecker.php",{ 
  			time: $("#duration").val()
  			}, 
  		function(data){
   		$('#info').html(data);
   		errordialog();
   		totimesetter();
 			});
 		});
 	$("#duration").focus(function() {
 		$('#duration').select();
  		});
  	$("#from").focus(function() {
 		$('#from').select();
  		});
  	$("#to").focus(function() {
 		$('#to').select();
  		});
 		
});




 $(document).ready(function(){
    		$("#jobpicker").autocomplete('visual/jobcompleter.php', {close: function(event,ui) {alerter();} });
    		$('#jobpicker').result(function(event, data, formatted) {
    			$('#thisjob').html($("#jobpicker").val());
     			setjobid();
				});
  });

$(document).ready(function(){
	$("#addjob").click(function() {
		$.post("core/timesetter.php", { 
  			from: $("#from").val(),
  			duration: $("#duration").val(),
  			action: "to"
  			}, 
  			function(data){
   		$('#to').val(data);
   		$.post("core/addjob.php",{ 
  				jid: $("#jobid").val(),
  				jdesc: $("#jobid").val(),
  				from: $("#from").val(),
  				to: $("#to").val(),
  				duration: $("#duration").val(),
  				note: $("#note").val(),
  				action: "validate"
  				}, 
  				function(data){
   				$('#info').html(data);
   				errordialog();
   				$.post("core/addjob.php",{ 
  						jid: $("#jobid").val(),
  						jdesc: $("#jobid").val(),
  						from: $("#from").val(),
  						to: $("#to").val(),
  						duration: $("#duration").val(),
  						note: $("#note").val(),
  						action: "add"
  					}, 
  					function(data){
   				loadtasks();
   		
 					});
   		
 			});
 			}); 
 		});	
});


 
 $(document).ready(function() {
 	$.post("visual/getattend.php", function(data){
 	$('#attend').html(data);
 	$(".editattend").editable("visual/setattendance.php", { 
            style  : "inherit"
  	});
 	});
 	
 });
 
 $(document).ready(function() {
  $("#computeattend").click(function() {
  	
  	$.post("core/computeattend.php", function(data){
  		
  		$('.editattend').html(data);
 			
  		});
 		
  	
  	
  	});
  
  });
  
  
  $(document).ready(function() {
  	$('#loadinfo').hide();
  });

 $(document).ready(function() {
  	$('#loadinfo').ajaxStart(function() {
  	$(this).show();
  	//$(this).text('Loading');
  	//$(this).removeClass('loaded');
  	//$(this).addClass('loading');
	});
	
	$('#loadinfo').ajaxStop(function() {
	$(this).hide(50);
  	//$(this).text('Loaded');
  	//$(this).removeClass('loading');
  	//$(this).addClass('loaded');
	});
  });
  
  
  $(document).ready(function() {
  
	
 
 
	$(document).bind("idle.idleTimer", function(){
	$('#idlinfo').text('user inactive');
	
 // function you want to fire when the user goes idle
	});
 
 
	$(document).bind("active.idleTimer", function(){
 // function you want to fire when the user becomes active again
 	$.post("core/sessioncheck.php", function(data){
  		if (data == 'terminated') {
  			//$('#idlinfo').html(data);
  			$(location).attr('href','index.php');
 			} else {
 			//$('#idlinfo').html('aaa');
 			}
  		});

	});
 
// pass the string 'destroy' to stop the timer
	//$.idleTimer('destroy');
  
  	$.idleTimer(3600000);
  	});
  
  	
//element visualisations
 
</script>
<?php
$user=new core_user;
?>
<img class="logo" src="logo_main_banner_small.png" alt="fasttimesheet logo"></img>

<div id="treecontainer"><div id="tree"></div></div>
<div id="right">

<div class="maindiv" id="loginfo"><p class="vertcenter"><?php echo $loc->logged_user;?>: <b><?php echo $user->getUserName($_SESSION['uid']);?> </b> <span id="settings_dialog" onclick="settings_dialog()">settings</span>
<br>
<form id="logoutform" action="index.php" method="POST">
<input type="submit" name="logout" value="log out" >
</form>

</p>

</div>
<div class="separator"></div>
<div class="maindiv" id="menu" >
<form action="index.php" method="POST"><input type="hidden" name="switch" value="attend"><input type="hidden" value="attendance"></form>
<form action="index.php" method="POST"><input type="hidden" name="switch" value="main"><input type="hidden" value="tasks"></form>

<div class="maindiv" id="picker">
<p><?php echo $loc->date;?>: <input class="myinputstyle" type="text" id="datepicker" value="<?php echo $_SESSION['date'];?>"><input class="button" type="button" name="previous_day" id="previous_day" value="<? echo $loc->previous; ?>"><input class="button"  type="button" name="next_day" id="next_day" value="<? echo $loc->next ?>"></p>
<p class="inline"><?php echo $loc->attendance;?>: <b id="attend"></b> <span id="computeattend"><?php echo $loc->computefromworkload;?></span> <form action="index.php" method="POST"><input type="submit" name="att" value="<? echo $loc->attendance_wiev; ?>"> <input type="hidden" name="switch" value="attend"></form>
</div>
<div class="insider"></div>
<div class="maindiv" id="thisjob_holder"><?php echo $loc->currentlyworking;?><h4 id="thisjob"></h4></div>
<div class="insider"></div>
<div class="maindiv" id="job_menu">
<p><?php echo $loc->job;?>: <input class="myinputstyle" type="text" id="jobpicker" value=""></p>
<form id="addjobform" action="" method="">
<input id="jobid" name="jobid" type="hidden" value="">
<p class="p_inline"><?php echo $loc->from;?> <input class="myinputstyle" id="from" type="text" name="from" value=""></p>
<p class="p_inline"><?php echo $loc->to;?> <input class="myinputstyle" id="to" type="text" name="to" value="" <?php if ($_SESSION['role'] == 3){echo 'disabled="true"';} ?>></p>
<p class="p_inline"><?php echo $loc->duration;?> <input class="myinputstyle" id="duration" type="text" name="duration" value="<?php echo $time_interval; ?>" <?php if ($_SESSION['role'] == 3){echo 'disabled="true"';} ?>></p>
<p class="p_inline"><?php echo $loc->note;?> <input class="myinputstyle" id="note" type="text" name="note" value=""></p>
<input id="addjob" name="addjob" type="button" class="button" value="<?php echo $loc->addjob_visual; ?>">
</form>
</div>


</div>
<div id="info"></div>
<div class="separator"></div>
<div class="maindiv" id="mainview"></div>
<div class="maindiv" id="settings"></div>
<div class="loaded" id="loadinfo"><table><tr><td><img src="loading.gif" alt="loading"></td> <td><span id="loadtext"> Loading </span></td></tr></table></div>
<?php
//echo date('m/d/Y');
require 'footer.php';
?>
</div>
<div title="choose job" id="changejob"></div>



<script>

 
</script>
</body>
</html>
